<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use App\Admin\Link;

use DB;

use Input;

class LinkController extends Controller
{
    //显示友情链接列表
    public function index() {
    	
    	$data = Link::orderBy('link_ob','desc')->get();
    	return view('admin.link.index',compact('data'));
    	
    }


    //添加
    public function add(){
    	//判断请求类型
        if(Input::method() == 'POST'){
            //处理
            $data = Input::except('uploadfile','file-2','_token','file');
     
            //写入数据
            $result = Link::insert($data);
            //转化bool类型
            return $result ? '1' : '0';
        }else{
            
            //展示视图
            return view('admin.link.add');
        }
    }


    //假删除用户（其实是把isdel字段改成1）
    public function del() {
    	
    	$id = $_GET['id']; 
    	$info = DB::table('link')->where('id','=',$id)->update(['isdel'=>1]);
    	
    }
    

    //修改用户信息
    public function edit() {
    	//判断
    	if(Input::method() == 'POST') {

    		$data = Input::except('_token','file');
    		
    		$result = Link::where('id',$data['id'])->update($data);
    		
    		return $result ? '1' : '0';
    		
    	} else {
    		
    		//获取数据
    		$id = $_GET['id'];
    		$data = Link::where('id',$id)->get();
    		
    		//展示视图
    		return view('/admin/link/edit',compact('data'));	
    	}	
    }  
    
}
